package com.farm.farming.controller;

import com.farm.entity.PageResult;
import com.farm.entity.Result;
import com.farm.entity.StatusCode;
import com.farm.farming.pojo.Cust_menu;
import com.farm.farming.service.Cust_menuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/custMenu")
@RestController
public class Cust_menuController {

    @Autowired
    private Cust_menuService cust_menuService;

    @RequestMapping("/findAll")
    public Result findAll(){

        List<Cust_menu> list = cust_menuService.findAll();

        return new Result(true, StatusCode.OK,"查询完成",list);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Cust_menu cust_menu){

        cust_menuService.add(cust_menu);

        return new Result(true,StatusCode.OK,"添加菜单完成");
    }

    @GetMapping("/deleteById")
    public Result deleteById(@RequestParam("id")Integer id){

        cust_menuService.delete(id);

        return new Result(true,StatusCode.OK,"删除菜单完成");
    }

    @PostMapping("/updateMenu")
    public Result updateMenu(@RequestBody Cust_menu cust_menu){

        cust_menuService.update(cust_menu);

        return new Result(true,StatusCode.OK,"修改完成");
    }

    @GetMapping("/findMenuById/{id}")
    public Result findMenuById(@PathVariable("id")Integer id){

        Cust_menu menu = cust_menuService.findById(id);

        return new Result(true,StatusCode.OK,"",menu);
    }

    @PostMapping("/findPage")
    public Result findPage(@RequestBody Cust_menu cust_menu,
                           @RequestParam(value = "page",defaultValue = "0",required = false)Integer currentPage,
                           @RequestParam(value = "size",defaultValue = "10",required = false)Integer size){

        PageResult<Cust_menu> page = cust_menuService.findPage(cust_menu, currentPage, size);

        return new Result(true,StatusCode.OK,"分页查询完成",page);
    }

}
